package com.huawei.bitfun;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.dbcp2.BasicDataSource;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
    public static void processData(JSONObject data) {
        System.out.println(data);
    }
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, SQLException {
//        Method method = Main.class.getMethod("processData", JSONObject.class);
//        method.setAccessible(true);
//        method.invoke(null, new JSONObject());
//        testAdd();
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName("org.sqlite.JDBC");
        dataSource.setUrl("jdbc:sqlite:C:\\Users\\shiwanheng\\IdeaProjects\\ProfilerExSql\\src\\main\\resources\\db\\profilerExSql.db");
        dataSource.setInitialSize(1);
        dataSource.setMaxTotal(1);
        Connection connection = dataSource.getConnection();
        PreparedStatement ps = connection.prepareStatement("DELETE FROM datasource WHERE id = ?");
        ps.setInt(1, 1);
        connection.close();
        int res = ps.executeUpdate();
        System.out.println(res);
    }

    private static void testAdd() throws SQLException {
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName("org.sqlite.JDBC");
        dataSource.setUrl("jdbc:sqlite:C:\\Users\\shiwanheng\\IdeaProjects\\ProfilerExSql\\src\\main\\resources\\db\\profilerExSql.db");
        dataSource.setInitialSize(1);
        dataSource.setMaxTotal(1);
        Connection connection = dataSource.getConnection();
        PreparedStatement ps = connection.prepareStatement("INSERT INTO datasource (name, path) VALUES(?,?)");
        ps.setString(1, "datasource1");
        ps.setString(2, "D:/test.db");
        int res = ps.executeUpdate();
        System.out.println(res);
    }

}